<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      background-color: #ccc;
    }
  </style>
</head>

<body>
  <div class="box"></div>

  <button class="btn">显示</button>
  <script>
    let box = document.querySelector('.box')
    let btn = document.querySelector('.btn')
    document.addEventListener('click', handleClick)
    btn.onclick = function () {
      box.style.display = 'block'
    }
    function handleClick (e) {
      if (!e.target.className && e.target.className !== 'box') {
        box.style.display = 'none'
      } else {

      }
    }
  </script>
</body>

</html>